﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class admin_cms_default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                Load_loaidiadanh();
            }


        }

    }
    protected void Load_loaidiadanh()
    {
        string check = string.Empty;

        string sql1 = "select * from video order by id desc";
        DataTable dtyahoo1 = DataAccess.ExeSQLToDataTable(sql1);
        if (dtyahoo1.Rows.Count > 0)
        {
            GridView1.DataSource = dtyahoo1;
            GridView1.DataBind();
        }

    }

    protected void grv_yahoo_click(object sender, CommandEventArgs e)
    {

        string IdDuLich = e.CommandArgument.ToString();
        string CheckName = e.CommandName.ToString();
        if (CheckName == "X")
        {

            //DataAccess.ExeNonStored("Yahoo_Delete", "@IdYahoo", IdYahoo);
            DataAccess.ExeNonSQL("delete from video where id='" + IdDuLich + "'");
            Response.Write("<script>alert('Bạn xóa thành công 1 bản ghi')</script>");
            Load_loaidiadanh();
        }
        else
        {
            DataTable dtgrv_yahoo = new DataTable();
            dtgrv_yahoo = DataAccess.ExeSQLToDataTable("select * from video where id='" + IdDuLich + "'");
            if (dtgrv_yahoo.Rows.Count > 0)
            {
             
                fckvideo.Value = dtgrv_yahoo.Rows[0][1].ToString();
                Session.Add("IdDuLich", IdDuLich);
            }
        }
    }
    protected void Yahoo_Insert(object sender, EventArgs e)
    {//
        string content = fckvideo.Value.ToString();
        // DataAccess.ExeNonStored("Yahoo_Insert", "@Name", Name, "@Nick", Nikc, "@Status", Status, "@Sort", Sort);
        string sql_insert_yahoo = "Insert into video(conntent) values(N'" + content + "')";
        DataAccess.ExeNonSQL(sql_insert_yahoo);
        Response.Write("<script>alert('Bạn thêm thành công 1 bản ghi')</script>");
        Load_loaidiadanh();
    }
    #region Load Drop theo đệ quy
    protected DataTable load_drop_process(DataTable dtDrop, DataTable dtnews, string IdParent, int level)
    {
        int countall = dtnews.Rows.Count;

        for (int i = 0; i < countall; i++)
        {
            if (dtnews.Rows[i][1].ToString() == IdParent)
            {
                string idMenu = dtnews.Rows[i][0].ToString();

                //Khai 1 bao doi tuong DataRow
                DataRow drItems;
                drItems = dtDrop.NewRow();

                drItems["name_menu"] = levelMenu(level) + dtnews.Rows[i][2].ToString();
                drItems["link_web"] = dtnews.Rows[i][3].ToString();
                dtDrop.Rows.Add(drItems);

                load_drop_process(dtDrop, dtnews, idMenu, level + 1);
            }
        }
        return dtDrop;
    }

    protected string levelMenu(int value)
    {
        string str = "";
        for (int i = 0; i < value; i++)
        {
            str += "*";
        }
        return str;
    }

    
    #endregion
    protected void yahoo_update(object sender, EventArgs e)
    {
        int idyahoo = Convert.ToInt32(Session["IdDuLich"].ToString());
        string connten = fckvideo.Value.ToString();
        //DataAccess.ExeNonStored("Yahoo_Update", "@IdYahoo", idyahoo, "@Name", Name, "@Nick", Nikc, "@Status", Status, "@Sort", Sort);
        string sqlupdate = "update video set conntent=N'" + connten + "', where Id='" + idyahoo + "'";
        DataAccess.ExeNonSQL(sqlupdate);
        Response.Write("<script>alert('Bạn sửa thành công 1 bản ghi')</script>");
        Load_loaidiadanh();
    }
}